package zjc.bookkeeping.minepage.aAssetaccount;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import zjc.bookkeeping.R;
import zjc.bookkeeping.activity.MainActivity;
import zjc.bookkeeping.db.DBManager;
import zjc.bookkeeping.db.MethodBean;

public class AssetAddaccountActivity extends AppCompatActivity {
    MethodBean methodBean;

    TextView title;
    EditText name;
    EditText money;
    EditText remark;
    EditText card;

    String items[]={ "选择全部账本", DBManager.getAccountName(DBManager.selectAccountId())};
    String extraString;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_asset_addaccount);

        title=findViewById(R.id.adtitle);
        name=findViewById(R.id.adname);
        money=findViewById(R.id.admoney);
        remark=findViewById(R.id.adremark);
        card=findViewById(R.id.adcard);

        //修改部分显示
        Modifydisplay();



    }
//新增账户时对应的名称
    private void Modifydisplay() {

        //获取传递的字符串值
        Intent intent =getIntent();
        extraString = intent.getStringExtra("acclass");

        switch (extraString){
            case "a_list_xj":
                title.setText("新增现金账户");
                name.setText("现金(可自由修改）");
                break;
            case "a_list_zfb":
                title.setText("新增支付宝账户");
                name.setText("支付宝(可自由修改）");
                break;
            case "a_list_wx":
                title.setText("新增微信账户");
                name.setText("微信(可自由修改）");
                break;
            case "a_list_yhk":
                title.setText("新增银行卡账户");
                name.setText("银行卡(可自由修改）");
                break;
            case "a_list_qqqb":
                title.setText("新增QQ钱包账户");
                name.setText("QQ钱包(可自由修改）");
                break;
            case "a_list_qt":
                title.setText("新增其他账户");
                name.setText("其他(可自由修改）");
                break;
        }
    }

    //返回新增资产账户页面
    public void backadd(View v){
        finish();
        Toast.makeText(this, "取消新增", Toast.LENGTH_SHORT).show();
    }


    //选择账本的弹窗
    public void selectledger(View v){
        AlertDialog.Builder dialog = new AlertDialog.Builder(AssetAddaccountActivity.this);
        dialog.setTitle("请选择生效账本");
        dialog.setIcon(R.drawable.ledger_switch);
        dialog.setPositiveButton("取消", null);
        dialog.setPositiveButton("确定", null);
        dialog.setMultiChoiceItems(items, null, new DialogInterface.OnMultiChoiceClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which, boolean isChecked) {

            }
        }).create();
        dialog.show();
    }

    //点击确认新增后返回资产账户页面
    public void backfinish(View v){
        methodBean = new MethodBean();
        methodBean.setMethod_name(name.getText().toString());
        methodBean.setMethod_money(Float.parseFloat(money.getText().toString()));
        methodBean.setMethod_remark(remark.getText().toString());
        methodBean.setMethod_card(card.getText().toString());
        methodBean.setMethod_image(extraString);

        DBManager.createMethod(methodBean);

        finish();
        Toast.makeText(this, "新增成功，请下拉刷新", Toast.LENGTH_SHORT).show();
//        Intent intent = new Intent(this, AssetaccountActivity.class);
//        startActivity(intent);

    }

}